//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __ELASTOS_UART_H__
#define __ELASTOS_UART_H__

#define COMPORT_AVAILABLE(comPort) \
        (ComPort1 == (comPort) || ComPort2 == (comPort) ||ComPort3 == (comPort) )

#define COMPORT_IOBASE(comPort) \
        ((ComPort1 == (comPort))? _UART1_IOBASE :\
        ((ComPort2 == (comPort))?  _UART2_IOBASE : _UART3_IOBASE))

#define IOADDR(pa)  ((virtaddr_t)((pa) - 0x70000000 + 0x80000000))


// UART Line Control Register (LCR)
#define ULCON_WL_5            0x00    // Word Length 5 Bits
#define ULCON_WL_6            0x01    // Word Length 6 Bits
#define ULCON_WL_7            0x02    // Word Length 7 Bits
#define ULCON_WL_8            0x03    // Word Length 8 Bits
#define ULCON_SB_1            0x00    // 1 Stop Bit
#define ULCON_SB_1_5          0x04    // 1.5 Stop Bit
#define ULCON_SB_2            ULCON_SB_1_5  // 2 Stop Bit
#define ULCON_NP              0x00    // No Parity
#define ULCON_OP              0x20    // Odd Parity
#define ULCON_EP              0x28    // Even Parity
#define ULCON_HP              0x30    // High Parity (Sticky)
#define ULCON_LP              0x38    // Low Parity (Sticky)
#define ULCON_IR              0x40    // Infrared mode

// UART IO base address
#define _UART1_IOBASE       ((ioport_t)IOADDR(0x7f005000))
#define _UART2_IOBASE       ((ioport_t)IOADDR(0x7f005400))
#define _UART3_IOBASE       ((ioport_t)IOADDR(0x7f005800))

// UART registers' address
#define _UART_ULCON(base)       ((ioport_t)((base) + 0x00))
#define _UART_UCON(base)        ((ioport_t)((base) + 0x04))
#define _UART_UFCON(base)       ((ioport_t)((base) + 0x08))
#define _UART_UMCON(base)       ((ioport_t)((base) + 0x0C))
#define _UART_UTRSTAT(base)     ((ioport_t)((base) + 0x10))
#define _UART_UERSTAT(base)     ((ioport_t)((base) + 0x14))
#define _UART_UFSTAT(base)      ((ioport_t)((base) + 0x18))
#define _UART_UMSTAT(base)      ((ioport_t)((base) + 0x1C))
#define _UART_UTXH(base)        ((ioport_t)((base) + 0x20))
#define _UART_URXH(base)        ((ioport_t)((base) + 0x24))
#define _UART_UBRDIV(base)      ((ioport_t)((base) + 0x28))

#endif // __ELASTOS_UART_H__
